package org.his.service.impl;

import java.util.List;

import org.his.entity.Medicine;
import org.his.mapper.MedicineMapper;
import org.his.service.MedicineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class MedicineServiceImpl implements MedicineService{
	@Autowired
	private MedicineMapper medicineMapper;
	public int addMedicine(Medicine addMedicine) {				
		int count = 0;
		Integer  checkInteger;
		try {
		if (addMedicine.getDrugname() != null) {
			checkInteger = queryByDrugname(addMedicine);
			if (checkInteger == 1) {
				count = -2;
			}else {
				count = medicineMapper.addMedicine(addMedicine);
			}
		}else {
			count = -1;
		}} catch (Exception e) {
			e.printStackTrace();
			count = -1;
		}		 
		return count;
	}
	
	public List<Medicine> queryByMedicalrecord(String medicalrecord) {
		
		return medicineMapper.queryByMedicalrecord(medicalrecord);
	}

	public int deleteByDrugname(String drugname) {
		
		int count = 0;
		if (drugname !=null) {
			count = medicineMapper.deleteByDrugname(drugname);
		} else {
			count = -1;
		}
		
		return count;
	}

	public Integer queryByDrugname(Medicine addMedicine) {
		Integer countInteger = -1;
		countInteger = medicineMapper.queryByDrugname(addMedicine);
		return countInteger;
	}

	
	
	

}
